package com.mingtu.jgspatrol.share;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.BottomPopupView;
import com.lxj.xpopup.util.XPopupUtils;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.databinding.LayoutShareBinding;

/**
 * @ClassName :
 * @Author : wkk
 * @Date : 2022-2-16 18:01:54
 * @Email : 1281573890@qq.com
 * @Eescription :
 */
public class BottomPopupShare extends BottomPopupView implements View.OnClickListener{
    private OnItemClickListener mOnItemClickListener = null;
    private LayoutShareBinding popupBinding;

    public BottomPopupShare(@NonNull Context context) {
        super(context);

    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.layout_share;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        popupBinding = LayoutShareBinding.bind(bottomPopupContainer.getChildAt(0));
        addClickListener(this, popupBinding.layoutWechat, popupBinding.layoutMoment, popupBinding.layoutFavorite, popupBinding.butCancle);
    }

    @Override
    protected void onShow() {
        super.onShow();
    }

    @Override
    protected void onDismiss() {
    }

    @Override
    protected int getMaxHeight() {
        return (int) (XPopupUtils.getScreenHeight(getContext()) * .7f);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_wechat:
                mOnItemClickListener.onItemClick(v, 0);
                break;
            case R.id.layout_moment:
                mOnItemClickListener.onItemClick(v, 1);
                break;
            case R.id.layout_favorite:
                mOnItemClickListener.onItemClick(v, 2);
                break;
            case R.id.but_cancle:
                mOnItemClickListener.onItemClick(v, 3);
                break;
        }
    }
    private void addClickListener(OnClickListener listener, View... views) {
        for (View view : views) {
            if (view != null) {
                view.setOnClickListener(listener);
            }
        }
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    public static interface OnItemClickListener {
        void onItemClick(View view, int position);
    }
}
